import 'package:flutter/material.dart';
import 'package:wuliu01/utils/token.dart';

class Setting extends StatefulWidget {
  const Setting({super.key});

  @override
  State<Setting> createState() => _SettingState();
}

class _SettingState extends State<Setting> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('系统设置'),
        toolbarHeight: 70,
        centerTitle: true,
        backgroundColor: Colors.white,
      ),
      body: Stack(
        alignment: Alignment.topCenter, // 子组件默认居中
        children: [
          //背景
          Container(color: const Color.fromARGB(255, 228, 228, 228)),
          //选项
          Column(
            children: [
              //选项
              Container(
                margin: EdgeInsets.only(top: 30),
                padding: EdgeInsets.only(
                  top: 19,
                  bottom: 22,
                  left: 18,
                  right: 13,
                ),
                width: 395,
                height: 300,
                //decoration: BoxDecoration(borderRadius: BorderRadius.circular(8)),
                color: const Color.fromARGB(255, 255, 255, 255),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Text('换绑手机', style: TextStyle(fontSize: 16)),
                        const Spacer(),
                        Image.asset('assets/ic_btn_more.png'),
                      ],
                    ),
                    Divider(
                      height: 30, // 控制分割线上下间距（非线条粗细）
                      thickness: 2, // 线条实际粗细
                      color: const Color.fromARGB(255, 228, 228, 228),
                      indent: 0, // 左侧缩进
                      endIndent: 0, // 右侧缩进
                    ),
                    Row(
                      children: [
                        Text('修改密码', style: TextStyle(fontSize: 16)),
                        const Spacer(),
                        Image.asset('assets/ic_btn_more.png'),
                      ],
                    ),
                    Divider(
                      height: 30, // 控制分割线上下间距（非线条粗细）
                      thickness: 2, // 线条实际粗细
                      color: const Color.fromARGB(255, 228, 228, 228),
                      indent: 0, // 左侧缩进
                      endIndent: 0, // 右侧缩进
                    ),
                    Row(
                      children: [
                        Text('消息通知设置', style: TextStyle(fontSize: 16)),
                        const Spacer(),
                        Image.asset('assets/ic_btn_more.png'),
                      ],
                    ),
                    Divider(
                      height: 30, // 控制分割线上下间距（非线条粗细）
                      thickness: 2, // 线条实际粗细
                      color: const Color.fromARGB(255, 228, 228, 228),
                      indent: 0, // 左侧缩进
                      endIndent: 0, // 右侧缩进
                    ),
                    Row(
                      children: [
                        Text('修改密码', style: TextStyle(fontSize: 16)),
                        const Spacer(),
                        Image.asset('assets/ic_btn_more.png'),
                      ],
                    ),
                    Divider(
                      height: 30, // 控制分割线上下间距（非线条粗细）
                      thickness: 2, // 线条实际粗细
                      color: const Color.fromARGB(255, 228, 228, 228),
                      indent: 0, // 左侧缩进
                      endIndent: 0, // 右侧缩进
                    ),
                    Row(
                      children: [
                        Text('清理缓存', style: TextStyle(fontSize: 16)),
                        const Spacer(),
                        Image.asset('assets/ic_btn_more.png'),
                      ],
                    ),
                  ],
                ),
              ),
              //退出
              const SizedBox(height: 20),
              ElevatedButton(
                style: ElevatedButton.styleFrom(
                  backgroundColor: const Color.fromARGB(255, 249, 249, 249),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10),
                  ),
                  minimumSize: Size(395, 50),
                ),
                onPressed: () => _showLogoutDialog(context),
                child: Text('退出', style: TextStyle(color: Colors.black)),
              ),
            ],
          ),

          //Text('层叠文字', style: TextStyle(color: Colors.white, fontSize: 24)),
        ],
      ),
    );
  }

  //弹窗
  void _showLogoutDialog(BuildContext context) {
    showDialog(
      context: context,
      barrierColor: Colors.black54, // 半透明遮罩
      builder:
          (context) => AlertDialog(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10),
            ),
            contentPadding: const EdgeInsets.fromLTRB(24, 24, 24, 16),
            content: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                const Text(
                  '确定要退出登录？',
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
                ),
                const SizedBox(height: 24),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    // 取消按钮
                    Expanded(
                      child: OutlinedButton(
                        style: OutlinedButton.styleFrom(
                          foregroundColor: Colors.grey[700],
                          side: BorderSide(color: Colors.grey[300]!),
                          padding: const EdgeInsets.symmetric(vertical: 12),
                        ),
                        onPressed: () => Navigator.pop(context),
                        child: const Text('取消'),
                      ),
                    ),
                    const SizedBox(width: 16),
                    // 退出按钮
                    Expanded(
                      child: ElevatedButton(
                        style: ElevatedButton.styleFrom(
                          backgroundColor: Colors.red,
                          foregroundColor: Colors.white,
                          padding: const EdgeInsets.symmetric(vertical: 12),
                        ),
                        onPressed: () {
                          // 实际退出登录逻辑
                          Navigator.pushNamed(context, '/exit');
                          print('执行退出登录操作');
                          TokenManager().removeToken();
                        },
                        child: const Text('退出'),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
    );
  }
}
